package com.cbs.android.component.application.activity;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.multidex.MultiDex;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import android.view.WindowManager;

import com.cbs.android.component.application.CBSApplication;
import com.cbs.android.component.application.R;
import com.cbs.android.component.log.L;


/**
 * Created by broche on 5/12/16.
 */
public class CBSLoadResActivity extends FragmentActivity {
    private static final String TAG = CBSLoadResActivity.class.getName();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        overridePendingTransition(R.anim.cbs_application_loadres, R.anim.cbs_application_loadres);
        setContentView(R.layout.cbs_application_loadres);
        new LoadDexTask().execute();
    }

    private class LoadDexTask extends AsyncTask {
        @Override
        protected Object doInBackground(Object[] params) {
            try {
                MultiDex.install(getApplication());
                L.e(TAG, "install finish");
                ((CBSApplication) getApplication()).installFinish(getApplication());
            } catch (Exception e) {
                L.e(TAG, "", e);
            }
            return null;
        }

        @Override
        protected void onPostExecute(Object o) {
            L.e(TAG, "get install finish");
            finish();
            System.exit(0);
        }
    }
}
